package com.asset.dispoal.commom.version.strategy.execute;

import com.asset.dispoal.commom.version.strategy.VersionStrategyServer;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.strategy.StrategyHandlerParam;
import tech.mhuang.pacebox.core.strategy.StrategyHandlerResult;

import java.util.Arrays;
import java.util.List;

/**
 * @author qr
 * @date 2022/2/18$
 */
@Component
public class InsertStrategyService implements VersionStrategyServer {
    @Override
    public StrategyHandlerResult<String> strategy(StrategyHandlerParam<String> strategyHandlerParam) {
        String sql = strategyHandlerParam.getData();


        String tableName = sql.substring(sql.toUpperCase().indexOf("INTO") + 5, sql.toUpperCase().indexOf("("));
        sql = sql.replace(tableName, tableName.trim() + "_version");
        return new StrategyHandlerResult<String>(true, sql.toString());
    }

    @Override
    public List<String> event() {
        return Arrays.asList("INSERT");
    }
}
